package cn.iune.backcenter.author.sysinfo;

import java.util.List;

import org.dom4j.DocumentException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONObject;

@Service
public class SysServiceImpl implements ISysService {
	
	@Autowired
	private ISysInfoService sysInfoService;
	@Autowired
	private IBillSettingService billSettingService;

	
	@Transactional
	@Override
	public void importXML(JSONObject data) throws DocumentException{
		/*
		//导入主表
		SystemXMLUtil systemXMLUtil = new SystemXMLUtil();
		List<SystemXML> systemXMLList = systemXMLUtil.getAll();
		for(SystemXML systemXML : systemXMLList){
			SysInfo sysInfo = new SysInfo();
			sysInfo.setfID(systemXML.getfID());
			sysInfo.setSystemCode(systemXML.getSystemCode());
			sysInfo.setSystemName(systemXML.getSystemName());
			sysInfo.setSystemDescribe(systemXML.getSystemDescribe());
			sysInfo.setItemPrice(systemXML.getItemPrice());
			sysInfo.setStatus(systemXML.getStatus());
			sysInfo.setVersion(systemXML.getVersion());
			dao.insert(sysInfo);
		}
		//导入子表
//		BillSettingUtil billSettingUtil = new BillSettingUtil();
		SystemBillXMLUtil systemBillXMLUtil = new SystemBillXMLUtil();
		List<SystemBillXML> SystemBillXML = systemBillXMLUtil.getAll();
		for(SystemBillXML systemBillXML : SystemBillXML){
			BillSetting billSetting = new BillSetting();
			billSetting.setfID(systemBillXML.getfID());
			billSetting.setfMasterID(systemBillXML.getfMasterID());
			billSetting.setBillType(systemBillXML.getBillType());
			billSetting.setBillTypeName(systemBillXML.getBillTypeName());
			billSetting.setPreChar(systemBillXML.getPreChar());
			billSetting.setCodeCount(systemBillXML.getCodeCount());
			billSetting.setCodeType(systemBillXML.getCodeType());
			billSetting.setCodeTypeLabel(systemBillXML.getCodeTypeLabel());
			billSetting.setAutoCode(systemBillXML.getAutoCode());
			billSetting.setAutoCodeLabel(systemBillXML.getAutoCodeLabel());
			billSetting.setCostingCode(systemBillXML.getCostingCode());
			billSetting.setCostingCodeLabel(systemBillXML.getCostingCodeLabel());
			billSetting.setRevOpay(systemBillXML.getRevOpay());
			billSetting.setRevOpayLabel(systemBillXML.getRevOpayLabel());
		    billSetting.setDirection(systemBillXML.getDirection());
		    billSetting.setDirectionLabel(systemBillXML.getDirectionLabel());
		    billSetting.setOrigin(systemBillXML.getOrigin());
		    billSetting.setOriginName(systemBillXML.getOriginName());
		    billSetting.setFlowType(systemBillXML.getFlowType());
		    billSetting.setFlowTypeLabel(systemBillXML.getFlowTypeLabel());
//		    billSetting.setWindowUrl(systemBillXML.getWindowUrl());
//		    billSetting.setWindowProcess(systemBillXML.getWindowProcess());
//		    billSetting.setWindowActivity(systemBillXML.getWindowActivity());

			billSetting.setVersion(systemBillXML.getVersion());
			
			billSettingUtil.insert(billSetting);
		}
		*/
	}
	
	@Transactional
	@Override
	public int deleteAll(){
		
		billSettingService.deleteAll();
		List<SysInfo> sysInfoList = sysInfoService.getAll();
		for(SysInfo sysInfo : sysInfoList){
			sysInfoService.delete(sysInfo.getfID());
		}
		return 0;
	}
	
	@Override
	public JSONObject getAppList() {
		JSONObject json = new JSONObject();
		json.put("code", 0);
		json.put("data", sysInfoService.getAppList()); 
		return json;
	}	

	
	
}
